<?php
namespace jy_farmer;
defined('BY_JYA') or exit('error');
/*
	消息提醒
*/
class notice extends \plugin{
	public function notice_payorder($order,$url=''){
		//发送订单生成通知给买方		
		$template_id=cfc('account')->get_tpl_template_id('OPENTM411984109','认养成功');
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('3534',[1,2,3,4],'payorder','认养成功','jy_farmer');
		}
		$member=cfc('core')->member_show($order['mid']);
		$message=array(
			'first'=>array('value'=>'认养成功！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$member['nickname']?:'匿名用户',"color" => "#4a5077"),
			'keyword2'=>array('value'=>$member['mobile']?:'无',"color" => "#4a5077"),
			'remark'=>array('value'=>'恭喜您认养成功。点击查看认养详情！',"color" => "#4a5077"),
		);
		if(!$url){
			$url=custom_url('jy_farmer/order/',true);	
		}
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'payorder','jy_farmer',$order['id']);
		}
		if($_SESSION['wxapp_id']){
			$template_id=cfc('wxapp_api')->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'payorder','jy_farmer',$order['id']);
		}
	}
	public function notice_cancelorder($order,$url=''){
		//发送订单生成通知给买方		
		$template_id=cfc('account')->get_tpl_template_id('OPENTM411984109','取消认养成功');
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('3534',[1,2,3,4],'cancelorder','取消认养成功','jy_farmer');
		}
		$member=cfc('core')->member_show($order['mid']);
		$message=array(
			'first'=>array('value'=>'取消认养成功！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$member['nickname']?:'匿名用户',"color" => "#4a5077"),
			'keyword2'=>array('value'=>$member['mobile']?:'无',"color" => "#4a5077"),
			'remark'=>array('value'=>'您已取消认养。点击查看认养详情！',"color" => "#4a5077"),
		);
		if(!$url){
			$url=custom_url('jy_farmer/order/',true);	
		}
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'cancelorder','jy_farmer',$order['id']);
		}
		if($_SESSION['wxapp_id']){
			$template_id=cfc('wxapp_api')->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'cancelorder','jy_farmer',$order['id']);
		}
	}
}
